package com.andy.android.usbmanager.data;

import android.os.Handler;
import android.os.Looper;

import java.util.ArrayList;
import java.util.List;

public enum GNRMCObservable {
    INSTANCE;
    private static final Handler mainHandler = new Handler(Looper.getMainLooper());

    private static final List<GNRMCObserver> observers = new ArrayList<>();

    public void register(GNRMCObserver observer) {
        if (!observers.contains(observer)) observers.add(observer);
    }

    public void unregister(GNRMCObserver observer) {
        observers.remove(observer);
    }

    public void onGNRMCChange(GNRMC gnrmc) {
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                for (GNRMCObserver observer : observers) {
                    observer.onGNRMCChanged(gnrmc);
                }
            }
        });
    }
}
